package com.lrkj.workorder.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.domain.entity.RepairProject;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.workorder.service.IRepairProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报修项目Controller
 *
 * @author yajun_ren
 * @date 2022-04-22
 */
@RestController
@RequestMapping("/workorder/repairProject")
@Api(tags = "报修项目")
public class RepairProjectController extends BaseController {
    @Autowired
    private IRepairProjectService repairProjectService;

    /**
     * 查询报修项目列表
     */
    @ApiOperation(value = "查询报修项目列表", notes = "查询报修项目列表")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairProject repairProject) {
        startPage();
        this.changeParameter(repairProject.getParams());
        List<RepairProject> list = repairProjectService.selectRepairProjectList(repairProject);
        return getDataTable(list);
    }

    /**
     * 导出报修项目列表
     */
    @ApiOperation(value = "导出报修项目列表", notes = "导出报修项目列表")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:export')")
    @Log(title = "报修项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RepairProject repairProject) {
        List<RepairProject> list = repairProjectService.selectRepairProjectList(repairProject);
        ExcelUtil<RepairProject> util = new ExcelUtil<RepairProject>(RepairProject.class);
        return util.exportExcel(list, "报修项目数据");
    }

    /**
     * 获取报修项目详细信息
     */
    @ApiOperation(value = "获取报修项目详细信息", notes = "获取报修项目详细信息")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(repairProjectService.selectRepairProjectById(id));
    }

    /**
     * 新增报修项目
     */
    @ApiOperation(value = "新增报修项目", notes = "新增报修项目")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:add')")
    @Log(title = "报修项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairProject repairProject) {
        return toAjax(repairProjectService.insertRepairProject(repairProject));
    }

    /**
     * 修改报修项目
     */
    @ApiOperation(value = "修改报修项目", notes = "修改报修项目")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:edit')")
    @Log(title = "报修项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairProject repairProject) {
        return toAjax(repairProjectService.updateRepairProject(repairProject));
    }

    /**
     * 删除报修项目
     */
    @ApiOperation(value = "删除报修项目", notes = "删除报修项目")
    @PreAuthorize("@ss.hasPermi('workorder:repairProject:remove')")
    @Log(title = "报修项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(repairProjectService.deleteRepairProjectByIds(ids));
    }


    /**
     * 获取报修项目下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(RepairProject repairProject) {
        repairProject.setStatus("0");
        List<RepairProject> repairProjects = repairProjectService.selectRepairProjectList(repairProject);
        return AjaxResult.success(repairProjectService.buildDeptTreeSelect(repairProjects));
    }
}
